package com.tanhua.app.controller;

import com.tanhua.app.service.CommentService;
import com.tanhua.app.service.QuanZiService;
import com.tanhua.mongo.Publish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class QuanZiController {

    @Autowired
    private QuanZiService quanZiService;
    @Autowired
    private CommentService commentService;

    @PostMapping(value = "/movements",name="发布动态")
    public ResponseEntity publishMovements(Publish publish, MultipartFile[] imageContent) throws IOException {

        return quanZiService.publishMovements(publish,imageContent);
    }

    @GetMapping(value = "/movements/all",name="查看自己的动态")
    public ResponseEntity findPublishAll(Integer page,Integer pagesize,Long userId) throws IOException {

        return quanZiService.findPublishAll(page,pagesize,userId);
    }


    @GetMapping(value = "/movements",name="查看好友的动态")
    public ResponseEntity findFriendPublish(Integer page,Integer pagesize) throws IOException {

        return quanZiService.findFriendPublish(page,pagesize);
    }

    @GetMapping(value = "/movements/recommend",name="查看推荐的人动态")
    public ResponseEntity findRecommendPublish(Integer page,Integer pagesize) throws IOException {
        return quanZiService.findRecommendPublish(page,pagesize);
    }












    /*以下功能 都是用户的行为 我们要做收集给大数据*/
    //浏览  +1
    @GetMapping(value = "/movements/{id}",name="评论内容回显")
    public ResponseEntity findByPublish(@PathVariable("id") String publishId) throws IOException {
        quanZiService.toBigDate(1,publishId);
        return quanZiService.findByPublish(publishId);
    }

    //点赞 +5
    @GetMapping(value = "/movements/{id}/like",name="点赞")
    public ResponseEntity likePublish(@PathVariable("id") String publishId) throws IOException {
        quanZiService.toBigDate(2,publishId);
        return quanZiService.likePublish(publishId);
    }

    //喜欢 +8
    @GetMapping(value = "/movements/{id}/love",name="喜欢")
    public ResponseEntity lovePublish(@PathVariable("id") String publishId) throws IOException {
        quanZiService.toBigDate(3,publishId);
        return quanZiService.lovePublish(publishId);
    }

    //评论 +10
    @PostMapping(value = "/comments",name="评论发布")
    public ResponseEntity saveInfo(@RequestBody Map<String,String> map) throws IOException {

        String publishId = map.get("movementId");
        String comment = map.get("comment");

        quanZiService.toBigDate(4,publishId);
        return commentService.saveInfo(publishId,comment);
    }

    //取消点赞 -5
    @GetMapping(value = "/movements/{id}/dislike",name="取消点赞")
    public ResponseEntity unlikePublish(@PathVariable("id") String publishId) throws IOException {
        quanZiService.toBigDate(5,publishId);
        return quanZiService.unlikePublish(publishId);
    }

    //取消喜欢 -8
    @GetMapping(value = "/movements/{id}/unlove",name="取消喜欢")
    public ResponseEntity unlovePublish(@PathVariable("id") String publishId) throws IOException {
        quanZiService.toBigDate(6,publishId);
        return quanZiService.unlovePublish(publishId);
    }

}
